GASP: a genetic algorithm for state preparation on quantum computers

The efficient preparation of quantum states is an important step in the execution of many quantum algorithms. In the noisy intermediate-scale quantum (NISQ) computing era, this is a significant challenge given quantum resources are scarce and typically only low-depth quantum circuits can be implemented on physical devices. We present a genetic algorithm for state preparation (GASP) which generates relatively low-depth quantum circuits for initialising a quantum computer in a specified quantum state. The method uses a basis set of \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$R_x$$\end{document}Rx, \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$R_y$$\end{document}Ry, \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$R_z$$\end{document}Rz, and CNOT gates and a genetic algorithm to systematically generate circuits to synthesize the target state to the required fidelity. GASP can produce more efficient circuits of a given accuracy with lower depth and gate counts than other methods. This variability of the required accuracy facilitates overall higher accuracy on implementation, as error accumulation in high-depth circuits can be avoided. We directly compare the method to the state initialisation technique based on an exact synthesis technique by implemented in IBM Qiskit simulated with noise and implemented on physical IBM Quantum devices. Results achieved by GASP outperform Qiskit’s exact general circuit synthesis method on a variety of states such as Gaussian states and W-states, and consistently show the method reduces the number of gates required for the quantum circuits to generate these quantum states to the required accuracy.

Quantum state preparation is key in many applications that require data input, such as finance [1][2][3] , chemistry 4-6 , bioinformatics 7 , machine learning 8,9 , and optimisation [10][11][12] . The ability to generate arbitrary quantum states efficiently and effectively, with high accuracy and low depth and gate count, will therefore be important in the future applications of quantum computing. Existing state preparation techniques [13][14][15][16][17] typically produce lengthy circuits with many qubit operations, or quantum gates, compromising their implementation on near-term hardware. In this paper, we present a genetic algorithm for state preparation (GASP) which creates circuits for state preparation to a specified accuracy and depth in an evolutionary framework. This work builds on a relatively old idea on the application of genetic algorithms to quantum circuit evolution 18 . For benchmarking purposes, of the methods that produce circuits for exact state preparation 13,19,20 , we focus here on the method by Shende, Bullock, and Markov (SBM) 14 , which has been encoded in the Qiskit library 21 . The SBM approach produces an n-qubit arbitrary state using a circuit containing no more than 2 n+1 − 2n CNOT gates. We benchmark the GASP method against Qiskit 21 for Gaussian states and W-states in the context of simulation with gate noise and implementation on physical devices. Because the GASP circuits have much lower depth by design, the prospects for implementation on physical Noisy Intermediate Quantum (NISQ) devices are better, as we will show by explicit examples.
A genetic algorithm is a classical optimisation technique that aims to mimic the process of biological evolution 22 . The basic structure of a genetic algorithm is to first establish a population of individuals to evolve. This population can be many individuals or only a single individual. Generic genetic algorithms usually have many individuals and use crossover, however, if the population has only a single individual it is asexual, and only uses mutation. Each individual is an attempted solution to the given problem and is defined by a 'chromosome' where each parameter in the chromosome represents a 'gene' . This population is then subject to an iterative process where the individuals are selected by some selection criteria (rank selection, roulette wheel selection, etc.), and the selected individuals are bred together, and/or mutated. Each iteration of the genetic algorithm is referred to as a 'generation' . For each generation, the fitness of each individual in the population is evaluated, by some objective fitness function, and the fittest individuals have the highest probability of being bred together, and/or mutated 23 . These individuals then form the next generation of the algorithm, in an effort to iteratively increase the maximum fitness. Generally, the algorithm is completed when a specific fitness is achieved, or when a given number of iterations are run without achieving a specific fitness. This method of optimisation allows solutions to be pulled out of local optima, and move towards global optima. The important aspects of the genetic algorithm approach are as follows (see section "Methods" for further details): www.nature.com/scientificreports/ Initial population/individual. In a sexual genetic algorithm the initial population is randomly generated with a specified population size parameter. Ideally, there is a considerable amount of divergence between different individuals, to allow for a broad area of the problem search space to be covered. In an asexual genetic algorithm, the initial population is only a single individual. Each individual in the population is instantiated with a chromosome defining a set of genes, the representation of these is subject to the problem being solved. Examples of possible chromosome representations include binary representations and list representations.
Crossover. Crossover is the process where two parents are bred together, producing a child that contains one-half of its genomic information from one parent, and one-half from the other. There are various methods of crossover in genetic algorithms, the main two being single-point crossover, and k-point crossover. The crossover point is where in the chromosome 'list' the chromosome is split. Single-point crossover is where the crossover point is chosen and the child's genomic information is taken from one parent before the crossover point, and one parent after the crossover point. k-point crossover is a slightly more generalised version of this process, where there are k crossover points and the genomic information of the child ends up being k + 1 sections alternating between parents 24 .

Mutation.
Mutation is the process where individual genes in an individual are randomly mutated, by some probability p, to increase genetic diversity in the population. In sexual genetic algorithms, the mutation rate is set low, as high mutation rates tend towards a primitive random search. In asexual genetic algorithms, the mutation rate is generally higher as it is the only means by which to introduce genetic diversity in the individual. The mutation operation allows the genetic algorithm to have increased genetic diversity, increasing the search space and allowing the algorithm to potentially escape local minima.
Selection. Selection is the process by which the fittest individuals are chosen for crossover. The procedure generally involves assigning a probability of selection to each individual based on their fitness. There are many selection methods; common methods include roulette wheel selection, rank selection, and tournament selection. In roulette wheel selection each individual is given a probability of being selected dependent on their fitness. This allows the fittest individuals to have the highest probability of passing genes on to the next generation. It also allows lucky unfit individuals to pass their genes on to the next generation, increasing genetic diversity. The advantage of this method is no genetic material is conserved. Rank selection sorts the individuals by fitness and chooses the fittest individuals for crossover. The advantage of this method is you can more quickly converge to an optimal solution by virtue of only taking the fittest individuals. Tournament selection randomly pairs individuals and selects the individual with the higher fitness of the two for crossover. This is an intermediary between the roulette wheel and rank selection, allowing potential faster convergence while maintaining a potentially higher level of genetic diversity.
In the quantum circuit space, the introduction of genetic algorithms has focused largely on producing circuits to generate specific unitaries 18,24-28 , and has been applied to quantum machine learning 29 . The flowchart describing GASP is depicted in Fig. 1. In this work, the genetic algorithm is designed to evolve quantum circuits for the task of state preparation. In this context, an individual is a quantum circuit, and a gene is a single quantum logic operation (gate) in the given quantum circuit.
The structure of the paper is as follows. Section "Results" will present the results, section "Methods" will describe the method presented in detail, and section "Discussion" our conclusions and potential future work.

Results
Gaussian states. Gaussian states have relatively low entanglement and are defined as, , µ is the mean, and σ is the standard deviation of the desired Gaussian. For the purposes of this paper, we let µ = 2 n 2 , and σ = 2 n 8 . In Fig. 2a we show an example GASP circuit, comparing the depth and gate count with that produced by Qiskit's initialise function. A comparison of the states produced by Qiskit's initialise function, and GASP, in the absence of noise, is shown in Fig. 2b for a 6 qubit Gaussian state. In the zero-noise regime, the data shows that the Qiskit method produces the target exactly as expected, and the GASP is within the specified fidelity tolerance (99% in this case). For the same 6 qubit Gaussian, a comparison of the states produced by Qiskit's initialise function, and GASP simulated, in the presence of noise (modelled from ibmq_guadalupe) is shown in Fig. 2c, 16,384 shots were used. It can be seen that GASP performs much better in reproducing the desired target state vector in the presence of noise, though not perfectly. This shows that a slight reduction in the accuracy of the circuit, for a large reduction in circuit depth improves the desired outcome state in the presence of noise. GASP producing circuits shorter by orders of magnitude allow more realistic circuits to be implemented on NISQ-era hardware. Figure 2d shows the comparison between GASP and Qiskit for Gaussian states, in terms of gate scaling vs. the number of qubits. Figure 2e shows the improved performance of the circuits generated by GASP relative to Qiskit when simulated with noise, and run on IBM's ibmq_guadalupe machine, averaged over 10 tests as the number of qubits varied from 2 to 10 (noting that this measure does not include the phase information).
(1) where n is the number of qubits. In Fig. 3a we show an example GASP circuit, comparing the depth and gate count with that produced by Qiskit's initialise function. A comparison of the produced states by Qiskit's initialise function, and GASP, with no noise, is shown in Fig. 3b. Figure 3c shows the comparison between Qiskit and GASP (99% fidelity) resultant distributions in the presence of noise for a 6 qubit W state. The noise model is that of IBM's ibmq_guadalupe machine. 16,384 shots were used. The grey dashed line is the exact distribution without noise, the orange bars are GASP, and the blue bars are Qiskit. Figure 3d shows the comparison between the Qiskit and GASP (99% fidelity) for W-states as the number of qubits varied from 2 to 10. Figure 3e shows the performance of the circuits generated by GASP and Qiskit when simulated with noise, averaged over 10 tests as the number of qubits varied from 2 to 10 noting that this measure does not include the phase information.
As can be seen in the results shown here, GASP consistently outperforms Qiskit in the number of total gates and the number of CNOT gates required; by more than two orders of magnitude in the higher qubit tests. It seems that GASP is a lower polynomial complexity in the number of gates required compared to Qiskit's initialisation method. It should be noted that the number of gates required for the Gaussian state generation is fewer than that of the W-states. This is likely due to Gaussian states being less entangled than W-states. It can be seen that the circuits produced by GASP have higher noise robustness than circuits produced by Qiskit's initialisation. However, the length of circuits produced by both techniques at high numbers of qubits have so many gates that the noise overwhelms the ability of the circuit to produce the desired state. It should also be noted that at useful fidelities (those above 50%), GASP outperforms Qiskit's initialisation.

Methods
In GASP, a gene is represented, and an individual is represented,  www.nature.com/scientificreports/ where each gene (i = 0 . . . n) represents a gate application, q t is the target qubit, G is the chosen gate type from {R x , R y , R z , CNOT} , q c is the control qubit if any, and θ is the rotation angle in the chosen gate. For a single qubit gate, q c is set to None. For a two-qubit gate q c is set to another qubit in the circuit, and θ is set to None, allowing the classical optimisation to only optimisation single-qubit rotation angles. The number of genes in an individual is dependent on how many gates the circuit contains. As such, a mutation in the genetic algorithm would be the changing of certain gates with a given probability.

|ψ(θ)
Crossover. The crossover method used in GASP is a simple 1-point crossover with one half from each parent, applied to every generation (i.e. crossover point is 50%). In the quantum circuit context, this results in a new circuit containing half the gates from the first individual, and half the gates from the second individual.
Mutation. Mutation in GASP is applied every generation. The default probability for mutation is 5% , however, this parameter can be varied dependent on the problem to be solved. The basic mutation of a quantum circuit changes certain genes in the individual to other genes, resulting in different gates for the quantum circuit, changing the resultant state vector.
Fitness. Given the target state vector, |ψ target � , and the resultant state vector of the current individual, |ψ( � θ) P i � , GASP searches for the individual whose circuit produces the highest fitness. The fitness is calculated by the cost function, the norm squared of the inner product between the target state vector and the individual's state vector, which is the similarity between the target state vector and the individual's state vector. The fitness of the individual will always be a value between 0 and 1.
Selection. The method of selection used in GASP is roulette wheel selection. This allows genetic diversity to be maintained through generations of the algorithm, while also increasing fitness. This is done by initially summing the total fitness of the entire population of individuals, f T , then giving each individual a normalised fitness relative to the fitness of the entire population, p(|ψ( � θ) P �) , i.e, The individuals in the next generation are then selected based on their respective fitnesses.
Algorithm. For a chosen |ψ target � , a population of individuals is produced each with a certain number of 'genes' based on the entanglement of the target state. The individual is the quantum circuit. Each 'gene' is one of the four gates identified in the universal set listed in section "Methods"; {R x , R y , R z , CNOT} . The fitness of each individual is then assessed with the fitness function. Crossover is then applied to the population, to produce new individuals, doubling the population. Each individual in the population is then 'mutated' at a probability of 5% . SLSQP optimisation 30 is then run on each individual in the population to find the optimal θ 's for each given individual. The population is then subject to roulette wheel selection, to select the individuals for the next generation, halving the population back down to its original size. This process is then repeated, iteratively increasing the best fitness of the population. If the desired fitness is not achieved within maxiter (1000 in the presented results) iterations of the last increase in fitness, the number of genes for each individual is increased by one, and the process restarts. Once a desired target state vector |ψ target � (which also determines the number of qubits) is selected GASP can be broken down into the following steps: a. The initial population {P} , of individuals, P i , is created, that dictates the trial state vectors |ψ( � θ) P i � , with the appropriate number of qubits and number of genes for the given state vector b. The fitness of the state vectors determined by each individual in the population: f (|ψ( � θ) P i �) = |�ψ target |ψ( � θ) P i �| 2 is assessed c. Crossover is applied to the population, generating |ψ( � θ) new � d. The entire population is mutated with probability p = 5%. e. Classical optimisation is run on each mutated individual to obtain the optimal θ values between 0 and 2π , which achieve the highest fitness for their generated circuit f. Roulette wheel selection is applied to the population, to select the individuals for the next generation based on their assessed fitness. g. Steps ii-vi are repeated until the desired fitness is achieved or maxiter (where maxiter is a parameter set prior to the start of the algorithm) iterations since the last increase in fitness was achieved (4) P i = [gene 1 , gene 2 , . . . , gene n ], In GASP, the genetic algorithm is being utilised to determine the course-grained optimisation of quantum circuit structure, while a much better fine-grained algorithm, SLSQP, was used for determining the optimal angles for each circuit structure generated. This allows the optimal, or at least close to optimal, fitness for each generated circuit structure to be achieved.

Discussion
In this paper, we have proposed and demonstrated a state preparation method based on a genetic evolutionary approach. Benchmarking GASP against Qiskit's initialisation method, the results show that in the noisy regime relevant to implementation on actual hardware, GASP significantly outperforms the exact approach through superior circuit compression, by more than an order of magnitude. As GASP is a stochastic algorithm, there is an increase in run time over the deterministic algorithms and an introduced uncertainty in the ability to produce a solution. However, the significant reduction in both the total gate count and the number of required CNOT gates may outweigh these for the application of GASP to the initialisation of quantum states in circuit lengths feasible on NISQ-era hardware. As GASP is a general technique that works for any given state, further work beyond this paper will include using GASP to generate more general quantum state preparation problems, such as amplitude-encoded image data, particle physics data, and biological data. Additionally, as this work is all classical simulation of quantum states, it would be interesting future work to develop a cost function so that GASP could be run on an actual quantum computer. Note: During the preparation of this work, a recent paper by Rindell et al. 31 studying state preparation using a genetic algorithm was posted on the arXiv. Their method is similar to the GASP approach presented here, though differs in that they used a Fast Non-dominated Sorting Genetic Algorithm implemented in the DEAP Python package 32 , and a different gate set of {R z (θ), X, √ X, CNOT} . They also do not use classical optimisation, instead opting to adjust θ by adding a value from a selected Gaussian distribution. Their method was applied to the production of Haar random states up to 5 qubits, demonstrating similar fidelity improvements in the presence of noise.

Data availability
The datasets generated during and/or analysed during the current study are available from the corresponding author on reasonable request.